package com.hzeng.util;

import java.io.File;

import javax.swing.filechooser.FileFilter;

public class myFileFilter extends FileFilter {

	private java.util.List<String> extensions;
	private String description;

	public myFileFilter(String[] exts, String desc) {
		if (exts != null) {
			extensions = new java.util.ArrayList<String>();

			for (String ext : exts) {
				extensions.add(ext.replace(".", "").trim().toLowerCase());
			}
		}
		description = (desc != null) ? desc.trim() : "Custom File List";
	}

	@Override
	public boolean accept(File f) {

		if (f.isDirectory())
		{
			return true;
		}

		if (extensions == null)
		{
			return false;
		}
			
		for (String ext : extensions) {
			if (f.getName().toLowerCase().endsWith("." + ext))
			{
				return true;
			}
		}

		return false;
	}

	@Override
	public String getDescription() {
		return description;
	}
}